package star.动态规划.数字翻译字符串;

public class TranslateNum {
    public static void main(String[] args) {
        new TranslateNum().translateNum(25);

    }

    public int translateNum(int num) {
        String s = String.valueOf(num);
        if (s.length()==1) return 1;
        int[] arr = new int[s.length()];
        arr[0] = 1;
        if (s.charAt(0)==1 || (s.charAt(0)=='2' && s.charAt(1)<'6')) arr[1] = 2;
        else arr[1] = 1;
        for (int i = 1; i < s.length()-1; i++) {
            if (s.charAt(i)==1 || (s.charAt(i)=='2' && s.charAt(i+1)<'6')){
                arr[i+1] = arr[i] + arr[i-1];
            }else {
                arr[i+1] = arr[i];
            }
        }
        return arr[s.length()-1];
    }
}
